package com.demo.sink;

import cn.hutool.json.JSONUtil;
import com.demo.domain.RealtimeEventEntity;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommand;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommandDescription;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisMapper;

/**
 * @author huangtao
 * @since 2022-10-18
 */
public class RealtimeTagRedisMapper<IN> implements RedisMapper<RealtimeEventEntity> {

    @Override
    public RedisCommandDescription getCommandDescription() {
        return new RedisCommandDescription(RedisCommand.HSET, "");
    }

    @Override
    public String getKeyFromData(RealtimeEventEntity s) {
        String tagName = "default";
        if (s.getAppActive() == 1) {
            tagName = "isAppActive";
        } else if (s.getMiniProgramActive() == 1) {
            tagName = "isMiniActive";
        }
        return tagName;
    }

    @Override
    public String getValueFromData(RealtimeEventEntity s)
    {
        return "1";
    }

    public String getAdditionalKey(RealtimeEventEntity s) {
        return "rt" + s.getUserId();
    }
}
